package com.wanjl.mq.listener;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author WanJl
 * @version 1.0
 * @title TopicListener
 * @description
 * @create 2025/2/10
 */
@Slf4j
@Component
public class TopicListener {
    
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "topic.queue1"), 
                    exchange = @Exchange(name = "mdxq.topic",
                            type = ExchangeTypes.TOPIC),
                    key = {"order.insert.#"}
            )
    })
    public void listenQueueMessage01(String message) {
        log.info("消费者01监听并接收到topic.queue1队列中的消息，并且只监听通配符order.#的消息----->{}",message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "topic.queue2"), 
                    exchange = @Exchange(name = "mdxq.topic",
                            type = ExchangeTypes.TOPIC), 
                    key = {"user.*"}
            )
    })
    public void listenQueueMessage02(String message) {
        log.info("消费者02监听并接收到topic.queue2队列中的消息，并且只监听统配符user.*的消息----->{}",message);
    }

}
